import requests
from lxml import etree
'''
需求
获取四大名著书的章节内容
'''
url = 'https://www.shicimingju.com/book/sanguoyanyi/1.html'
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36',
}
res = requests.get(url, headers=headers)
tree = etree.HTML(res.content.decode())
text = ''.join(tree.xpath('//div[@class="card bookmark-list"]//text()'))
# print(text)
with open('章节.txt', 'w', encoding='utf-8') as f:
    f.write(text.replace(' ', ''))